<?php
/**
* Copyright 2009 Waag Society <http://www.waag.org>
* This file is part of Annotrax.
*
* Annotrax is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Annotrax is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Annotrax.
* If not, see http://www.gnu.org/licenses/gpl.html
*/
class Default_Model_VideoInfoMapper extends At_Model_Mapper{
    protected $tableName =  'video_info';

	/**
	 * Find existing video_info from DB.
	 */
	public function find( Default_Model_VideoInfo $info ){
		$result = $this->getTable()->find( $info->movieId );

		if( count( $result ) > 0 ){
			foreach( $result->current()->toArray() as $key => $value ){
				$info->$key = $value;
			}
		}
	}

	/**
	 * Save or update info
	 *
	 * @param Default_Model_Annotation $annotation The annotation to save
	 * @return void
	 */
    public function save( Default_Model_VideoInfo $video ){
		$info = (object) $video->toArray();

		$values = array(
			'movie_id'			=> $info->movieId,
			'duration'			=> $info->duration,
			'content_duration'	=> $info->contentDuration,
			'video_framerate'	=> $info->videoFramerate,
			'video_width'		=> $info->videoWidth,
			'video_height'		=> $info->videoHeight,
			'audio_samplerate'	=> $info->audioSamplerate,
			'audio_channels'	=> $info->audioChannels
		);

		$this->getTable()->insert( $values );
    }
}
